Vector¶

Vector is base class of other vector like classes. It represents a series of vectors.

In [1]:
from py3d import Vector
Vector()
Out[1]:
Vector([], dtype=float64)
In [3]:
Vector([0, 0, 0, 0])
Out[3]:
Vector([0, 0, 0, 0])
In [5]:
Vector([1, 2, -4])
Out[5]:
Vector([ 1,  2, -4])
In [7]:
Vector([1, 2, 3], (2,))
Out[7]:
Vector([[1, 2, 3],
        [1, 2, 3]])
In [9]:
import py3d
py3d.Vector([1, 2, 0, 3], ())
Out[9]:
Vector([1, 2, 0, 3])
In [10]:
Vector([1], (2,))
Out[10]:
Vector([[1],
        [1]])
In [12]:
V32 = Vector([
    [1, 3],
    [2, -9],
    [0.1, -3]])
V32
Out[12]:
Vector([[ 1. ,  3. ],
        [ 2. , -9. ],
        [ 0.1, -3. ]])

Get unit vector

In [13]:
V32.U
Out[13]:
Vector([[ 0.31622777,  0.9486833 ],
        [ 0.21693046, -0.97618706],
        [ 0.03331483, -0.99944491]])

Get length of vectors

In [14]:
V32.L
Out[14]:
array([[3.16227766],
       [9.21954446],
       [3.0016662 ]])
In [16]:
from numpy import allclose
assert allclose(V32.U.L, [[1], [1], [1]])

Get homogeneous vector

In [17]:
V32.H
Out[17]:
Vector([[ 1. ,  3. ,  1. ],
        [ 2. , -9. ,  1. ],
        [ 0.1, -3. ,  1. ]])

Get a series of random vectors

In [19]:
import py3d
py3d.Vector.Rand(2,3,4)
Out[19]:
Vector([[[0.49131834, 0.10336087, 0.50760776, 0.07097313],
         [0.41463367, 0.91502551, 0.54208339, 0.04520718],
         [0.58076083, 0.56924251, 0.89093911, 0.6569055 ]],

        [[0.06596884, 0.02334244, 0.72493364, 0.05977239],
         [0.68940789, 0.20783542, 0.05668877, 0.04774758],
         [0.59399828, 0.63195717, 0.41348648, 0.78559023]]])
In [21]:
import py3d
py3d.Vector([[0,0],[1,2],[3,4]]).diff()
Out[21]:
Vector([[1, 2],
        [2, 2]])

Read pcd file

In [23]:
import py3d
py3d.read_pcd("py3d/doc/ascii.pcd").xyz.as_point()
Out[23]:
In [24]:
import py3d
pcd = py3d.read_pcd("py3d/doc/binary.pcd")
pcd.xyz.as_point()
Out[24]:
In [25]:
pcd.to_pcd("test.pcd")